#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=5e3+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn],col[maxn],cnt=0;
LL dp[maxn][maxn];
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL n;cin>>n;
   for(LL i=1;i<=n;i++) cin>>a[i];
   for(LL i=2;i<=n+1;i++){
      if(a[i]!=a[i-1]){
         col[++cnt]=a[i-1];
      }
   }
   memset(dp,0x3f,sizeof(dp));
   for(LL i=1;i<=cnt;i++){
      dp[i][i]=0;
   }
   for(LL len=2;len<=cnt;len++){
       for(LL l=1;l+len-1<=cnt;l++){
           LL r=l+len-1;
           if(col[l]==col[r]){
              dp[l][r]=min(dp[l+1][r-1]+1,dp[l][r]);
           }
           else{
                dp[l][r]=min(dp[l][r],dp[l+1][r]+1);
                dp[l][r]=min(dp[l][r],dp[l][r-1]+1);
           }
       }
   }
   cout<<dp[1][cnt]<<"\n";
   return 0;
}
